package com.qyhl.webtv.module_microvideo.shortvideo.classic.list;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.microvideo.ClassicProgramBean;
import com.qyhl.webtv.module_microvideo.common.VideoUrl;

import java.util.List;

public class ClassicListModel implements ClassicListContract.ClassicListModel {
    private ClassicListPresenter mPresenter;

    public ClassicListModel(ClassicListPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String cateId, String page) {
        EasyHttp.get(VideoUrl.GET_CLASSIC_LIST)
                .params("cateId", cateId)
                .params("page", page)
                .execute(new SimpleCallBack<List<ClassicProgramBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何服务队！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取列表失败，请重新尝试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<ClassicProgramBean> beanList) {
                        if (beanList != null && beanList.size() > 0) {
                            mPresenter.setList(beanList, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何服务队！", !page.equals("1"));
                        }
                    }
                });
    }
}
